package com.wu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.wu.dao.OrgBaseDao;
import com.wu.pojo.po.orgPo.OrgBase;
import com.wu.pojo.dto.OrgFuzzyDTO;
import com.wu.pojo.vo.DataVo;
import com.wu.service.OrgBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrgBaseServiceImpl implements OrgBaseService {

    @Autowired
    OrgBaseDao orgBaseDao;


    @Override
    public OrgBase selectOne(OrgBase orgBase) {
        return orgBaseDao.queryOne(orgBase);
    }


    @Override
    public List<OrgBase> selectList(OrgBase orgBase) {
        return orgBaseDao.selectList(orgBase);
    }


    @Override
    public List<OrgBase> selectFuzzy(OrgFuzzyDTO orgFuzzyDTO) {
        return orgBaseDao.selectFuzzy(orgFuzzyDTO);
    }

    @Transactional
    @Override
    public boolean insertOrg(OrgBase orgBase) {
        if (null == orgBase || "".equals(orgBase.getOrgId())) {
            throw new RuntimeException("c:插入用户失败，机构id不能为空！");
        }
        try {
            int i = orgBaseDao.insertOrg(orgBase);
            if (i == 1) {
                return true;
            } else {
                throw new RuntimeException("a:插入用户失败！" + orgBase);
            }
        } catch (Exception e) {
            throw new RuntimeException("b:插入用户失败：" + e.getMessage());
        }
    }

    @Transactional
    @Override
    public boolean updateOrg(OrgBase orgBase) {
        if (null == orgBase || "".equals(orgBase.getOrgId())) {
            throw new RuntimeException("c:机构信息更新失败，机构id不能为空！");
        }
        try {
            int i = orgBaseDao.updateOrg(orgBase);
            if (i == 1) {
                return true;
            } else {
                throw new RuntimeException("a:机构信息更新失败！" + orgBase);
            }
        } catch (Exception e) {
            throw new RuntimeException("b:机构信息更新失败：" + e.getMessage());
        }
    }


    @Override
    public OrgBase selectById(String orgId) {
        return orgBaseDao.selectById(orgId);
    }


    @Override
    public String selectMobileByOrgId(String orgId) {
        return orgBaseDao.selectMobileByOrgId(orgId);
    }


    @Override
    public List<OrgBase> selectCheckList() {
        return orgBaseDao.selectCheckList();
    }


    @Override
    public OrgBase queryOrgByUserId(String userId) {
        return orgBaseDao.queryOrgByUserId(userId);
    }


    @Override
    public List<String> selectAreaList() {
        return orgBaseDao.selectAreaList();
    }


    @Override
    public List<String> selectOrgTypeList() {
        return orgBaseDao.selectOrgTypeList();
    }


    @Override
    public List<String> selectBusiTypeList() {
        return orgBaseDao.selectBusiTypeList();
    }


    @Override
    public DataVo selectCompleteData(String remark, String type) {
        return orgBaseDao.selectCompleteData(remark,type);
    }

}
